package cn.xscrum.demo.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.xscrum.common.annotation.Log;
import cn.xscrum.common.enums.BusinessType;
import cn.xscrum.demo.domain.Od;
import cn.xscrum.demo.service.IOdService;
import cn.xscrum.common.core.controller.BaseController;
import cn.xscrum.common.core.domain.AjaxResult;
import cn.xscrum.common.utils.poi.ExcelUtil;
import cn.xscrum.common.core.page.TableDataInfo;

/**
 * 线网OD乘客出行人次分布Controller
 * 
 * @author cyb
 * @date 2020-11-25
 */
@Controller
@RequestMapping("/demo/od")
public class OdController extends BaseController
{
    private String prefix = "demo/od";

    @Autowired
    private IOdService odService;

    @RequiresPermissions("demo:od:view")
    @GetMapping()
    public String od()
    {
        return prefix + "/od";
    }

    /**
	 * 查询线网OD乘客出行人次分布列表
     */
    @RequiresPermissions("demo:od:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Od od)
    {
        startPage();
        List<Od> list = odService.selectOdList(od);
        return getDataTable(list);
    }

    /**
	 * 导出线网OD乘客出行人次分布列表
     */
    @RequiresPermissions("demo:od:export")
    @Log(title = "线网OD乘客出行人次分布", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Od od)
    {
        List<Od> list = odService.selectOdList(od);
        ExcelUtil<Od> util = new ExcelUtil<Od>(Od.class);
        return util.exportExcel(list, "od");
    }

    /**
	 * 新增线网OD乘客出行人次分布
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
	 * 新增保存线网OD乘客出行人次分布
     */
    @RequiresPermissions("demo:od:add")
    @Log(title = "线网OD乘客出行人次分布", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Od od)
    {
        return toAjax(odService.insertOd(od));
    }

    /**
	 * 修改线网OD乘客出行人次分布
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Od od = odService.selectOdById(id);
        mmap.put("od", od);
        return prefix + "/edit";
    }

    /**
	 * 修改保存线网OD乘客出行人次分布
     */
    @RequiresPermissions("demo:od:edit")
    @Log(title = "线网OD乘客出行人次分布", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Od od)
    {
        return toAjax(odService.updateOd(od));
    }

    /**
	 * 删除线网OD乘客出行人次分布
     */
    @RequiresPermissions("demo:od:remove")
    @Log(title = "线网OD乘客出行人次分布", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(odService.deleteOdByIds(ids));
    }
}
